home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / object / get_bounds.pro next >
Text File  |  1997-07-08  |  4KB  |  114 lines

  1. ;+
  2. ; NAME:
  3. ;       GET_BOUNDS
  4. ;
  5. ; PURPOSE:
  6. ;       This procedure fills in the xrange, yrange, and zrange vectors
  7. ;       that represent the overall data ranges of the objects within
  8. ;       the given tree.
  9. ;
  10. ; CATEGORY:
  11. ;       Object graphics.
  12. ;
  13. ; CALLING SEQUENCE:
  14. ;       GET_BOUNDS, oObj, xrange, yrange, zrange
  15. ;
  16. ; INPUTS:
  17. ;       oObj - An instance of an IDLgrModel or IDLgrGraphic.  The bounds
  18. ;               to be computed will include this object plus all of its
  19. ;               children.
  20. ; OUTPUTS:
  21. ;       xrange: A two-element vector, [xmin, xmax], representing the
  22. ;               overall range of the X data values of the objects in
  23. ;               the tree.
  24. ;       yrange: A two-element vector, [ymin, ymax], representing the
  25. ;               overall range of the Y data values of the objects in
  26. ;               the tree.
  27. ;       zrange: A two-element vector, [zmin, zmax], representing the
  28. ;               overall range of the Z data values of the objects in
  29. ;               the tree.
  30. ;
  31. ; MODIFICATION HISTORY:
  32. ;       Written by:     DD, February 1997.
  33. ;-
  34. PRO get_bounds, oObj, xrange, yrange, zrange, CTM=ctm
  35.  
  36.     IF (OBJ_ISA(oObj, 'IDLgrModel')) THEN BEGIN
  37.         ; Update current transformation matrix.
  38.         oObj->GetProperty, TRANSFORM=modelCTM
  39.         IF (N_ELEMENTS(ctm) EQ 0) THEN BEGIN
  40.             ctm = modelCTM
  41.         ENDIF ELSE BEGIN
  42.             ctm = modelCTM # ctm
  43.         ENDELSE
  44.  
  45.         ; Step thru children of the model.
  46.         oChildArr = oObj->IDL_Container::Get(/ALL, COUNT=nKids)
  47.         IF (nKids GT 0) THEN BEGIN
  48.             ; Get first child's range.
  49.             oChild = oChildArr[0]
  50.             get_bounds, oChild, xrange, yrange, zrange, CTM=ctm
  51.  
  52.             IF (nKids GT 1) THEN BEGIN
  53.                 FOR i=1,nKids-1 DO BEGIN
  54.                     oChild = oChildArr[i]
  55.                     get_bounds, oChild, kidX, kidY, kidZ
  56.                     xrange[0] = xrange[0] < kidX[0]
  57.                     xrange[1] = xrange[1] > kidX[1]
  58.                     yrange[0] = yrange[0] < kidY[0]
  59.                     yrange[1] = yrange[1] > kidY[1]
  60.                     zrange[0] = zrange[0] < kidZ[0]
  61.                     zrange[1] = zrange[1] > kidZ[1]
  62.                 ENDFOR
  63.             ENDIF
  64.         ENDIF ELSE BEGIN
  65.             MESSAGE, 'IDLgrModel object has no children. Zeroing Range.', $
  66.                      /INFORMATIONAL
  67.             xrange=[0.0,0.0]
  68.             yrange=[0.0,0.0]
  69.             zrange=[0.0,0.0]
  70.         ENDELSE
  71.  
  72.     ENDIF ELSE IF (OBJ_ISA(oObj, 'IDLgrGraphic')) THEN BEGIN
  73.         oObj->GetProperty, XRANGE=graphicX, YRANGE=graphicY, ZRANGE=graphicZ
  74.  
  75.         ; Ensure we have a transformation matrix.
  76.         IF (N_ELEMENTS(ctm) EQ 0) THEN BEGIN
  77.             ctm = oObj->GetCTM()
  78.         ENDIF ELSE BEGIN
  79.             ; Include any coordinate conversion.
  80.             oObj->GetProperty, XCOORD_CONV=xs, YCOORD_CONV=ys,ZCOORD_CONV=zs
  81.             tmpTrans = [[xs[1],  0,   0,  xs[0]],$
  82.                         [ 0,   ys[1], 0,  ys[0]],$
  83.                         [ 0,      0,zs[1],zs[0]],$
  84.                         [ 0,      0,  0,    1  ]]
  85.             ctm = tmpTrans # ctm
  86.         ENDELSE
  87.  
  88.         ; Consider all eight points transformed by CTM.
  89.         FOR i=0,7 DO BEGIN
  90.             p = [ graphicX[(i AND 1)],     $
  91.                   graphicY[((i/2) AND 1)], $
  92.                   graphicZ[((i/4) AND 1)], $
  93.                   1.0] # ctm
  94.             IF (p[3] NE 0.0) THEN p = p / p[3]  ; Divide by W.
  95.             IF (i EQ 0) THEN BEGIN
  96.                 pmin = p
  97.                 pmax = p
  98.             ENDIF ELSE BEGIN
  99.                 pmin = pmin < p
  100.                 pmax = pmax > p
  101.             ENDELSE
  102.             xrange = [pmin[0], pmax[0]]
  103.             yrange = [pmin[1], pmax[1]]
  104.             zrange = [pmin[2], pmax[2]]
  105.         END
  106.  
  107.         nKids = 0
  108.         oChild = OBJ_NEW()
  109.     ENDIF ELSE BEGIN
  110.         MESSAGE, 'Object must be an IDLgrModel or IDLgrGraphic.'
  111.     ENDELSE
  112.  
  113. END
  114.